package com.genius.core.manager;

import java.util.List;
import java.util.Set;

import com.genius.core.dao.StudentDAO;
import com.genius.model.Batch;
import com.genius.model.Student;
import com.genius.model.StudentLevel;
import com.genius.model.StudentPayment;
import com.genius.model.Teacher;

/**
 * TODO Description
 * 
 * @author Manish Rathi [manish_rathi2001@yahoo.com]
 * @version 1.0
 */
public class StudentManagerImpl implements StudentManager {

	StudentDAO studentDao = null;
    
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    


	/**
	 * @return Returns the studentDao.
	 */
	public StudentDAO getStudentDao() {
		return studentDao;
	}

	/**
	 * @param studentDao The studentDao to set.
	 */
	public void setStudentDao(StudentDAO studentDao) {
		this.studentDao = studentDao;
	}
	
	public void createStudent(Student student){
		studentDao.createStudent(student);
	}

    public List searchStudent(String firstName, String lastName){
        return studentDao.getStudents(firstName, lastName);
    }
    
    public List searchStudent(String batchId){
        return studentDao.getStudentsForBatch(batchId);
    }


	public void addStudentPayment(StudentPayment studentPayment) {

		studentDao.createStudentPayment(studentPayment);
	}

	public Student getStudent(String studentId) {
		return studentDao.getStudent(studentId);
		//return null;
	}

	public List getStudentPaymentDetails(String studentId) {
		return studentDao.getStudentPaymentDetails(studentId);
	}

    public void addBatch(Batch batch)
    {
        
        
   /*     if(batch.getId() != null || batch.getId().equals("")) {
            Batch b = this.studentDao.getBatch(batch.getId());
            Set set = b.getStudents();
            batch.setStudents(set);
        }*/
        
        this.studentDao.createBatch(batch);
        
        
    }

    public List getStudentLevelDetails(String studentId)
    {
        this.studentDao.getStudentLevelDetails(studentId);
        return null;
    }

    public List getBatchList(int active)
    {
        List l = this.studentDao.getBatchList(active);
        int size = l.size();
        for (int i=0; i< size; i++ ){
            Batch b = (Batch)l.get(i);
            List sList = this.studentDao.getStudentsForBatch(b.getId());
            b.setStudents(sList);
        }
        System.out.println("DAO batchList" + l.size());
        return l;  
    }

    public void addStudentToBatch(String batchId, List studentIds)
    {
        this.studentDao.addStudentsToBatch(batchId, studentIds);
        
    }
    
    /**
     * Add Student Level
     * @param studentLevel
     * @param studentIds
     */
    void addStudentLevelDetails(StudentLevel studentLevel, List studentIds){
    	if (studentIds != null && studentIds.size() > 0)
    	{
    		for (int i=0; i<studentIds.size(); i++ ) {
    			StudentLevel temp = getNewStudentLevel (studentLevel);
    			temp.setStudentId((String)studentIds.get(i));
    			this.studentDao.createStudentLevel(temp);
    		}
    	}
    	
    	
    }

    private StudentLevel getNewStudentLevel(StudentLevel studentLevel) {
    	StudentLevel temp = new StudentLevel();
    	temp.setBookCharges(studentLevel.getBookCharges());
    	temp.setFees(studentLevel.getFees());
    	temp.setLevelId(studentLevel.getLevelId());
    	temp.setDiscount(studentLevel.getDiscount());
    	temp.setFeesReceiptNumber(studentLevel.getFeesReceiptNumber());
    	temp.setBookChargesReceiptNumber(studentLevel.getBookChargesReceiptNumber());
		return temp;
	}

	public void changeStudentLevel(List studentIds, StudentLevel level)
    {
        this.studentDao.createStudentLevel(level);
    }

    public Batch getBatch(String batchId)
    {
        return this.studentDao.getBatch(batchId);
        
    }

    public void addTeacher(Teacher teacher)
    {
        this.studentDao.addTeacher(teacher);
        
    }

    public List getTeacherList()
    {
       return this.studentDao.getTeacherList();
    }


}
